package com.admin.common;

import com.admin.common.biz.ModelUseStatus;

import java.util.UUID;

public class CommonUtils {

    public static boolean checkNumber(String value) {
        String regex = "^(-?[1-9]\\d*\\.?\\d*)|(-?0\\.\\d*[1-9])|(-?[0])|(-?[0]\\.\\d*)$";
        return value.matches(regex);
    }

    public static boolean checkUperCase(String value) {
        for (int i = 0, lenght = value.length(); i < lenght; i++) {
            if (!Character.isUpperCase(value.charAt(i))) return false;
        }
        return true;
    }

    public static boolean checkLowerCase(String value) {
        for (int i = 0, lenght = value.length(); i < lenght; i++) {
            if (!Character.isLowerCase(value.charAt(i))) return false;
        }
        return true;
    }

    public static String createId() {
        return UUID.randomUUID().toString();
    }

    /**
     *
     * @param val
     * @return
     */
    public static ModelUseStatus matchModelUseStatus(Integer val) {
        if (ModelUseStatus.USE.value == val) return ModelUseStatus.USE;
        if (ModelUseStatus.DRAFT.value == val) return ModelUseStatus.DRAFT;
        if (ModelUseStatus.EXPIRED.value == val) return ModelUseStatus.EXPIRED;
        return ModelUseStatus.DRAFT;

    }
}
